package cloudEntity.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * @program: Smart School
 * @ClassName ResultEntity
 * @description:  统一数据返回类.
 * @author: 陈智博
 * @create: 2025-04-05 21:17
 * @Version 1.0
 **/
@Data
public class ResultUtils<T> implements Serializable {

    private int code;
    private String msg;
    private T data;
    private Long timestamp;

    public static <T> ResultUtils<T> success(String msg) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(200);
        result.setMsg(msg);
        result.setData((T) "null");
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> success(T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(200);
        result.setMsg("success");
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> success(String msg,T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> success(T data, String msg) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(200);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }



    public static <T> ResultUtils<T> success(int code , String msg, T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> success(String msg, int code, T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> failed(String msg) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(400);
        result.setMsg(msg);
        result.setData((T) "null");
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> failed(String msg,T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(400);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> failed(T data, String msg) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(400);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }


    public static <T> ResultUtils<T> failed(int code , String msg, T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

    public static <T> ResultUtils<T> failed( String msg, int code, T data) {
        ResultUtils<T> result = new ResultUtils<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        result.setTimestamp(System.currentTimeMillis());
        return result;
    }

}
